﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace comdiinfo
{
    public abstract class G64Element<T>
    {
        public String elementName { get; set; }
        public G64ElementStatus elementStatus { get; set; }
        public StringBuilder elementStatusText = new StringBuilder();
        public List<String> extraWarnings = new List<string>();
        public List<String> extraErrors = new List<string>();
        public int trackNo { get; set; }
        public bool isHalfTrack { get; set; }
        private G64Element() { }
        public G64Element(int trackNo)
        {
            this.trackNo = trackNo;
            this.isHalfTrack = (trackNo % 2 != 1);
        }
        public T ElementValue { get; set; }
        public abstract void LoadData(ref G64ImageData imgData, int srcOffset, int count);
        public abstract void CheckValue();
        public void AddExtraWarning(String warningText)
        {
            extraWarnings.Add(warningText);
        }
        public void AddExtraError(String errorText)
        {
            extraErrors.Add(errorText);
        }
        public void SetStatusText(ref StringBuilder warningText, ref int warningCount, ref StringBuilder errorText, ref int errorCount)
        {
            CheckValue();         
            switch (elementStatus)
            {
                case G64ElementStatus.Ok:
                    break;
                case G64ElementStatus.Unchecked:
                    errorCount++;
                    errorText.AppendLine(String.Format("{0} is not checked!", elementName));
                    break;
                case G64ElementStatus.Warning:
                    warningCount++;
                    warningText.Append(elementStatusText);
                    break;
                case G64ElementStatus.Error:
                    errorCount++;
                    errorText.Append(elementStatusText);
                    break;
                default:
                    break;
            }
            foreach (String s in extraWarnings)
            {
                warningText.AppendFormat("{0} {1}", elementName, s);
                warningText.AppendLine();
                warningCount++;
            }
            foreach (String s in extraErrors)
            {
                errorText.AppendFormat("{0} {1}", elementName, s);
                errorText.AppendLine();
                errorCount++;
            }
        }
    }
}
